package com.cyzy.service.impl;

import com.cyzy.mapper.UserMapper;
import com.cyzy.pojo.TrainUser;
import com.cyzy.service.UserService;
import com.cyzy.utils.Md5Utils;
import com.cyzy.utils.MybatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

@Service
public class UserServiceImpl implements UserService {


    @Autowired
    private UserMapper userMapper;




    //登录
    @Override
    public TrainUser login(String userAcc, String userPwd) {
        TrainUser trainUsers = userMapper.login(userAcc, Md5Utils.md5(userPwd));
        return trainUsers;
    }

    //注册
    @Override
    public int addUser(TrainUser trainUser) {
        if(userMapper.getUserByAcc(trainUser.getUserAcc()) == null){
            Md5Utils.md5(trainUser.getUserPwd());
            trainUser.setUserStatus(0);
            trainUser.setPapersType("居民身份证");
            int i = userMapper.addUser(trainUser);
            return i;
        }
        return 0;
    }

    //修改用户信息
    @Override
    public int updateUser(TrainUser trainUser) {
        return userMapper.updateUser(trainUser);
    }


}
